home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_3a.arc / RECT.CLS < prev    next >
Text File  |  1989-02-22  |  909b  |  40 lines

  1. // rect.cls    Rectangle class.  uses two Points to define a rectangle.
  2. //
  3. // (c) Aspen Scientific 1989. All Rights Reserved.
  4. // Author: Vaughn Vernon
  5.  
  6. #ifndef _RECTANGLE_CLASS
  7.  
  8. # define _RECTANGLE_CLASS    1
  9.  
  10. # include "point.cls"
  11.  
  12. // Rectangle class
  13.  
  14. class Rectangle {
  15.  
  16. protected:
  17.     Point    op;    // origin Point
  18.     Point    cp;    // corner Point
  19. public:
  20.     Rectangle(Point & o, Point & c) { op = o; cp = c; }
  21.     Rectangle()        { op = Point(0,0); cp = Point(0,0); }
  22.     ~Rectangle()        { }
  23.  
  24.     Point &    origin()    { return op; }
  25.     Point & origin(Point &p){ return op = p; }
  26.     Point & corner()    { return cp; }
  27.     Point & corner(Point &p){ return cp = p; }
  28.     Point    extent()    {
  29.         Point p(cp.x() - op.x(), cp.y() - op.y());
  30.         return p;
  31.     }
  32.     int    height()    { return cp.x() - op.x(); }
  33.     int    width()        { return cp.y() - op.y(); }
  34.  
  35.     // draw() is protocol: derived class responsibility
  36.     virtual void draw()    { }
  37. };
  38.  
  39. #endif
  40.